<?php
include('config.php');
if(!isset($_COOKIE[md5('islogin')])){
require("login.php");
die();
}
if(!isset($_GET['x'])){
echo'参数错误,','id不存在！';
die();
}
?>
<html>
<head>
    <meta charset="utf-8">
    <title>后台管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="bootstrap.css" rel="stylesheet">
    <!--[if lt IE 9]>
      <script src="//cdnjs.bootcss.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
    <![endif]-->
	<style type="text/css">
      body {
		font-family:Microsoft Yahei,Simhei !important;
        padding-top: 20px;
        padding-bottom: 40px;
      }

      .container-narrow {
        margin: 0 auto;
        max-width: 1024px;
      }
    </style>
	</head>
  <body>
    <div class="container-narrow">

      <div class="masthead">
        <ul class="nav nav-pills pull-right">
          <li><a href="admin.php">后台</a></li>
          <li><a href="?do=out">退出</a></li>
        </ul>
        <h3 class="muted">后台管理</h3>
      </div>

      <hr>
<?php
if(@$_GET['do']=="edit"){
$row = $zxsblog_data[$_GET['x']]; 
?>
<?php if(!empty($msg))echo $msg;?>
      <div class="jumbotron">
        修改网址<br/>
		<form method="post" action="?do=dedit&x=<?php echo $_GET['x']?>">
		<input type="text" placeholder="名称" name="name" value="<?php echo $row['1'];?>">
		<input type="text" placeholder="网址，不带http" name="url" value="<?php echo $row['0'];?>">
		<input type="text" placeholder="关键词" name="keyword" value="<?php echo $row['3'];?>">
		<br/>描述<br/>
		<textarea rows="2" style="width:630px" name="desc"><?php echo $row['2'];?></textarea><br/>
        <button class="btn btn-success">提交</button>
		</form>
      </div>

      <hr>
<?php
}elseif(@$_GET['do']=="dedit"){
    @$fp = fopen(DATA_F,"w");
    if(!$fp){
        echo "system error";
    }else {
	  $row = $zxsblog_data[$_GET['x']]; 
	  $ofiledata = $row['0']. "<>" .$row['1']. "<>" .$row['2']. "<>" .$row['3'];
      $nfiledata = $_POST['url'] . "<>" . $_POST['name'] . "<>" . $_POST['desc'] . "<>" . $_POST['keyword'];
	  $filedata = str_replace($ofiledata,$nfiledata,DATA);
           
            fwrite($fp,$filedata);
            fclose($fp);
			echo "<h2>修改成功！</h2>",'<a href="admin.php">返回后台首页</a>';
    }
}elseif($_GET['do']=="del"){
$fp = fopen(DATA_F,"w");
    if(!$fp){
       echo "system error";
    }else {
	  $row = $zxsblog_data[$_GET['x']]; 
	  $ofiledata = $row['0']. "<>" .$row['1']. "<>" .$row['2']. "<>" .$row['3'] . '\n';
      $nfiledata = '';
	  $filedata = preg_replace('{' . $ofiledata . '}',$nfiledata,DATA);
            fwrite($fp,$filedata);
            fclose($fp);
			echo "<h2>删除成功！</h2>",'<a href="admin.php">返回后台首页</a>';
    }
echo $filedata;
}elseif($_GET['do']=="bkdata"){
$filename = DATA_F;
function download_file($archivo, $downloadfilename = null) {

    if (file_exists($archivo)) {
        $downloadfilename = $downloadfilename !== null ? $downloadfilename : basename($archivo);
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . $downloadfilename);
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($archivo));

        ob_clean();
        flush();
        readfile($archivo);
        exit;
    }

}
}
download_file(DATA_F,"bak.txt")
?>
      <div class="footer">
        <p>? 中学生站长联盟 2013 by快乐家园</p>
      </div>

    </div> <!-- /container -->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="//cdnjs.bootcss.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="bootstrap.js"></script>

  

</body></html>